//
//  EFPayTypeChooseViewCell.m
//  EnjogFood
//
//  Created by guocheng on 2017/5/28.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFPayTypeChooseViewCell.h"
#import "EFPayTypeChooseViewItem.h"

@interface EFPayTypeChooseViewCell()

@property(strong,nonatomic) UILabel* titleLabel;
@property(strong,nonatomic) UIButton* selectButton;
@property(strong,nonatomic) UIView* lineView;

@end


@implementation EFPayTypeChooseViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = [UIColor whiteColor];
        [self initView];
    }
    return self;
}

-(void)initView{
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.selectButton];
    [self.contentView addSubview:self.lineView];
}

-(void)layoutSubviews{
    [super layoutSubviews];
    self.titleLabel.left = 20;
    self.titleLabel.top = 14;
    
    self.selectButton.top = (self.height - self.selectButton.height)/2;
    self.selectButton.left = kScreenWidth - self.selectButton.width - 20;
    
    self.lineView.top = self.titleLabel.bottom + 15;
}


-(void)setObject:(EFPayTypeChooseViewItem *)item{
    [self.titleLabel setText:item.title];
    if(item.isSelect){
        [self.selectButton setSelected:true];
    }else{
        [self.selectButton setSelected:false];
    }
}

- (UIButton *)selectButton{
    if (!_selectButton) {
        _selectButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 22.f, 22.f)];
        [_selectButton setImage:IMG(@"cartlist_Unselected_icon") forState:UIControlStateNormal];
        [_selectButton setImage:IMG(@"cartlist_selected_icon") forState:UIControlStateSelected];
        [_selectButton setImage:IMG(@"cartlist_failure_icon") forState:UIControlStateDisabled];
        [_selectButton addTarget:self action:@selector(onClickSelectBtn) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectButton;
}

-(UILabel*)titleLabel{
    if(_titleLabel == NULL){
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 17)];
        _titleLabel.font = [UIFont systemFontOfSize:13];
        _titleLabel.textColor =kBlack333;
    }
    return _titleLabel;
}

-(UIView*)lineView{
    if(_lineView == NULL){
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth , 1)];
        _lineView.backgroundColor = kBlackDDD;
        
    }
    return _lineView;
}


-(void)onClickSelectBtn{
    self.selectButton.selected = !self.selectButton.selected;
    if(self.selectblock){
        self.selectblock(self.titleLabel.text);
    }
}
@end
